include("interface/userdata.lua")
include("shared.lua")
//include("other/setmodelplayer.lua")
include("other/npcplayer.lua")

//DIR_RIGHT = 0
//DIR_LEFT = 1

function GM:Initialize()

	//self:PlayerModel()
//self.BaseClass:PlayerSpawn( ply )
	self.BaseClass:Initialize()

	//self.Direction = DIR_RIGHT;
	
	gui.EnableScreenClicker(true)
end

hook.Remove("GUIMousePressed", "SuperDOFMouseDown")
hook.Remove("GUIMouseReleased", "SuperDOFMouseUp")

function GM:GUIMousePressed(mc)
	if (mc == MOUSE_LEFT) then LocalPlayer():ConCommand("+attack")
	elseif (mc == MOUSE_RIGHT) then LocalPlayer():ConCommand("+attack2")
	end
end

function GM:GUIMouseReleased(mc)
	if (mc == MOUSE_LEFT) then LocalPlayer():ConCommand("-attack")
	elseif (mc == MOUSE_RIGHT) then LocalPlayer():ConCommand("-attack2")
	end
end

function GM:CalcView( ply, origin, angles, fov )

	local a = ply:GetAngles()
	a.Pitch = 0
	ply:SetAngles(a)

	return self.BaseClass:CalcView(ply, origin, angles, fov)

end

/* function GM:CreateMove( cmd )

	local vpos = LocalPlayer():GetPos() + Vector(0,0,64)
	
	local ppos = vpos:ToScreen()
	local ppos = Vector( ppos.x, ppos.y, 0 )
	local mpos = Vector( gui.MouseX(), gui.MouseY(), 0 )

	local aim = (mpos - ppos):Angle()

	local ang = Angle(0,0,0)

	if (mpos.x < ppos.x) then
		aim:RotateAroundAxis( Vector(0,0,1), -90)
		ang.Pitch = -aim.Yaw	
		ang.yaw = 180;
		//cmd:SetForwardMove( -cmd:GetSideMove() )
	else	
		ang.Pitch = aim.Yaw		
		ang.yaw = 0;
		//cmd:SetForwardMove( cmd:GetSideMove() )
	end
	
	cmd:SetViewAngles( ang )
	//cmd:SetSideMove( 0 )
	
end
*/

function GM:CreateMove( cmd )

	local vpos = LocalPlayer():GetPos()
	
	local ppos = vpos:ToScreen()
	local ppos = Vector( ppos.x, ppos.y, 0 )
	local mpos = Vector( gui.MouseX(), gui.MouseY(), 0 )

	local skv = gui.ScreenToVector( gui.MouseX(), gui.MouseY() )
	local cam = LocalPlayer():GetNetworkedEntity("topScrollCam")

	local aim = (ppos - mpos):Angle()

	aim:RotateAroundAxis( Vector(0,0,1), 360)

	aim.Pitch = 360

	if (cam != NULL) then	
		local tr = {}
		tr.start = cam:GetPos()
		tr.endpos = cam:GetPos() + (skv * 4096)
		tr.filter = { cam, LocalPlayer() }

		local tr_res = util.TraceLine(tr)
		if (tr_res.HitEntity) then
			aim.Pitch = (tr_res.HitEntity:GetPos() - LocalPlayer:GetPos()) : Angle().Pitch
		end
	end

	local ang = Angle(0,0,0)

	ang.Yaw = -aim.Yaw
	ang.Roll = 0

	cmd:SetViewAngles( ang )
	
end

function GM:HUDPaint()
	self:DrawNames()
end